import StringUtils from "../../../utils/StringUtils";

let constants = require('../../../common/Constants.js');
let network_utils = require('../../../http/NetworkUtils.js');
let umfToast = require('../../../utils/UmfToast');
import * as stateUtils from '../../../model/StateUtils';
import * as regexUtils from '../../../utils/RegexUtils';
import * as umfUtils from '../../../utils/UmfUtils';
import PickerUtils from '../../../model/PickerUtils';
import pickerView from '../../../common/view/pickerview/pickerView';
import location from '../../../common/code/pickerList/location';
import busTypes from '../../../common/code/pickerList/busTypes';
import TimeUtils from '../../../utils/TimeUtils';
import { saveAgentCache } from '../../../model/CacheUtils';

import { $Toptips, $Toast } from '../../../components/CompRouter';

const FromTypes = {
    FROM_LIST: "agentList",
    FROM_SEARCH: "agentSearch"
};

var app = getApp();
Page(Object.assign({
    data: {
        //商户id
        storeId: "",
        //店铺状态
        storeState: {},

        //基本信息列表
        baseInfoArr: _getBaseInfoArr(this),
        //营业执照信息列表
        noInfoArr: _getNoInfoArr(this),
        //开通产品信息列表
        productsArr: _getProductsArr(),
        //照片展示信息
        photoInfoData: {},
    },

    onLoad: function (options) {

        this.setData({
            storeId: options.storeId,
            fromType: options.fromType,
            // curDate: TimeUtils.formatTime(),
            yesDate: TimeUtils.getLatestDate(1),
        });
        this._requestDetails();

	    this._initPickerView();
        //this.initLinkagePicker([busTypes, location]);
    },
    /**
     * 增加产品---POS
     * radio取值：长期/截止日期
     */
    // addProduct:function(){
    //   wx.navigateTo({
    //     url: '../../basisInfo/openPos/openPos?posFrom=detail&storeId=' + this.data.storeId,
    //   })
    // },
    /**
     * 收款人证件有效期---2017.11.8旭阳新需求
     * radio取值：长期/截止日期
     */
    payeeRadioValidChange:function(e){
      if (e.detail.value == "2099-09-09") {
        this.setData({
          payeeDeadDate: false,
        })
      } else {
        let baseArr = this.data.baseInfoArr
        for(let ite in baseArr){
          if (baseArr[ite].tag=="payeeInidcardValid"){
            baseArr[ite].content = ""
          }
        }
        this.setData({
          payeeDeadDate: true,
          payeeInidcardValid: "",
          baseInfoArr:baseArr
        })
      }
    },
    /**
     * 经营者证件有效期---2017.11.8旭阳新需求
     * radio取值：长期/截止日期
     */
    storeManRadioValidChange: function (e) {
      if (e.detail.value == "2099-09-09") {
        this.setData({
          storeManDeadDate: false,
          storeManIdentityValid:e.detail.value
        })
      } else {
        let noInfoArr = this.data.noInfoArr
        for (let ite in noInfoArr) {
          if (noInfoArr[ite].tag == "storeManIdentityValid") {
            noInfoArr[ite].content = ""
          }
        }
        this.setData({
          storeManDeadDate: true,
          storeManIdentityValid: "",
          noInfoArr: noInfoArr
        })
      }
    },


    /**
     * 点击产品
     * @param ress
     */
    tapProduct: function (ress) {
      // let tag = ress.currentTarget.dataset.binddata.tag
        // if (this.data.storeState.isPos) {
        //     return;
        // }
        // if(tag=='impay'){
          let pageState = "";
          if (this.data.type == 1) {
            pageState = "desployRateDisable";
          } else if (this.data.fromType === FromTypes.FROM_SEARCH) {
            pageState = "desployAllDisable";
          } else if (this.data.canMobileModify) {
            pageState = "desploy";
          } else {
            pageState = "desployRateDisable";
          }
          wx.navigateTo({
            url: '/pages/basisInfo/openImPay/openImPay?storeId=' + this.data.storeId
            + '&pageState=' + pageState
          });
        // }else {
          
        // }        
    },

    /**
     * 点击照片资料
     * @param ress
     */
    tapPhoto: function (ress) {
        if (this.data.storeState.isPos) {
            return;
        }

        let params = {
            storeId: this.data.storeId
        };
        network_utils.buildRequest(constants.Interfaces.FUNC_MERCHANT_DETAIL, params, {
            doHttpSucess: (response) => {
                if (constants.RetCodes.SUCCESS === response.retCode) {
                    let {
                        payeeName, storeMan, storeType, isAuthorize, payeeCardPhotoFrontUrl, payeeCardPhotoConUrl, categoryCardPhotoFrontUrl,
                        categoryCardPhotoCon, shopSignFrontUrl, shopInUrl, storeLicenseNoUrl, authCertUrl
                    } = response;
                    let photoInfoData = {
                        storeId: this.data.storeId,
                        payeeName: payeeName,
                        storeMan: storeMan,
                        storeType: storeType,
                        isAuthorize: isAuthorize,
                        payeeCardPhotoFront: encodeURIComponent(payeeCardPhotoFrontUrl),
                        payeeCardPhotoCon: encodeURIComponent(payeeCardPhotoConUrl),
                        categoryCardPhotoFront: encodeURIComponent(categoryCardPhotoFrontUrl),
                        categoryCardPhotoCon: encodeURIComponent(categoryCardPhotoCon),
                        shopSignPhotoFront: encodeURIComponent(shopSignFrontUrl),
                        shopSignPhotoCon: encodeURIComponent(shopInUrl),
                        busiLicensePhoto: encodeURIComponent(storeLicenseNoUrl),
                        authCertPhoto: encodeURIComponent(authCertUrl)
                    };

                    let pageState = "";
                    if (this.data.fromType === FromTypes.FROM_SEARCH) {
                        //展示
                        pageState = "desploy";
                    } else {
                        //正常修改
                        pageState = "normal";
                    }
                    wx.navigateTo({
                        url: './modifyPhotoInfo/modifyPhotoInfo?photoInfoData=' + JSON.stringify(photoInfoData) + "&pageState=" + pageState
                    });
                    return true;
                }
                return false;
            }
        }).send();
    },

    /**
     * 身份证输入监听
     * @param e
     * @returns {*}
     */
    bindIDChange: function (e) {
        return umfUtils.formatIDCard(e.detail.value);
    },

    /**
     * 日期输入监听
     * @param e
     */
    bindDateChange: function (e) {
        let id = e.currentTarget.id;
        this.setData({
            [id]: e.detail.value,
            // payeeInidcardValid:e.detail.value
        });
    },

    /**
     * pickerview确定回调
     * @param idx
     * @param ret
     * @param code
     */
    onConfirmCB: function (idx, ret, code) {
        if (idx === 0) {
            this.setData({
                storeCategory: code.join(",")
            });
        } else if (idx === 1) {
            this.setData({
                storeAddress: code.join(",")
            });
        }
    },

    /**
     * 提交修改
     * @param e
     */
    onSubmit: function (e) {
        let params = e.detail.value;
        let storeState = this.data.storeState;
        if (!this.data.payeeDeadDate) {
          this.setData({
            payeeInidcardValid: "2099-09-09"
          })
        }else{
          this.setData({
            payeeInidcardValid: params.payeeInidcardValid
          })
        }
        if (this._checkForm(params)) {
          
            let httpParams = {
                //用于推送模版消息的formId
                formId: e.detail.formId,
                state: storeState.code,
                storeId: this.data.storeId,
                payeeName: params.payeeName,
                payeeMobile: params.payeeMobile,
                payeeIdentity: params.payeeIdentity,
                payeeInidcardValid: this.data.payeeInidcardValid ? this.data.payeeInidcardValid : params.payeeInidcardValid,
            };

            if (storeState.storeingDone) {
                //店铺信息
                httpParams.storeShortName = params.storeShortName;
                httpParams.storeCategory = this.data.storeCategory;
                httpParams.storeAddress = this.data.storeAddress;
                // httpParams.storeCategory = PickerUtils.getLinkedCodeByHZ(busTypes, params.storeCategory).join(",");
                // httpParams.storeAddress = PickerUtils.getLinkedCodeByHZ(location, params.storeAddress).join(",");
                httpParams.storeFullAddress = params.storeFullAddress;
                httpParams.email = params.storeEmail;
                // httpParams.phone = params.phone;//固话
                httpParams.labelOne = params.labelOne;
                httpParams.labelTwo = params.labelTwo;

                let storeType = this.data.noInfoArr.length > 0 ? "1" : "0";
                httpParams.storeType = storeType;
                if (storeType === "1") {
                  if (!this.data.storeManDeadDate) {
                    this.setData({
                      storeManIdentityValid: "2099-09-09"
                    })
                  }
                    httpParams.licenseNo = params.licenseNo;
                    httpParams.storeName = params.storeName;
                    httpParams.storeMan = params.storeMan;
                    httpParams.storeManIdentity = umfUtils.removeSpace(params.storeManIdentity);
                    httpParams.storeManIdentityValid = this.data.storeManIdentityValid ? this.data.storeManIdentityValid : params.storeManIdentityValid;
                    httpParams.registerDate = this.data.registerDate;
                    httpParams.storeKind = params.storeKind;
                    httpParams.registerAddress = params.registerAddress;
                }
            }
            //缓存代理商邮箱及最近标签选项
            this._saveStoreEmail(params.storeEmail);
            this._saveAnnotations(params.labelOne, params.labelTwo);
            this._requestSubmit(httpParams);
        }
    },

    _checkForm(params) {
        //证件有效期 不能校验，因为之前录入的证件有可能过期了。
        //改为可以校验
      if (!this.data.payeeInidcardValid && !params.payeeInidcardValid){
        $Toptips.error({ text: "请选择收款人证件有效期" });
        return false
      }
        let storeState = this.data.storeState;
        // [结算账单优化工单] 校验标签
        if (storeState.storeingDone && StringUtils.safeTrim(params.labelOne).length <= 0 && StringUtils.safeTrim(params.labelTwo).length > 0) {
            $Toptips.error({text: "请输标签一内容"});
            return false;
        }

        let regexArr = [];
        storeState.storeingDone && regexArr.push([params.storeShortName, constants.RegexTypes.MERCHANT_NAME]);
        // storeState.storeingDone && regexArr.push([params.phone, constants.RegexTypes.FIXLINE]);// 固话
        // regexArr.push([params.payeeName, constants.RegexTypes.PAYEE_NAME]);
        // regexArr.push([umfUtils.removeSpace(params.payeeIdentity), constants.RegexTypes.ID_CARD]);
        regexArr.push([params.payeeMobile, constants.RegexTypes.MOBILE]);
        storeState.storeingDone && regexArr.push([params.storeFullAddress, constants.RegexTypes.DETAIL_ADD]);
        //[立马付运营优化二期] 商户邮箱有的场合校验
        storeState.storeingDone && params.storeEmail && regexArr.push([params.storeEmail, constants.RegexTypes.LINKTELEMAIL]);
        if (this.data.noInfoArr.length > 0) {
          if (!this.data.storeManIdentityValid && !params.storeManIdentityValid){
            $Toptips.error({ text: "请选择经营者证件有效期" });
            return false
          }
            regexArr.push([params.licenseNo, constants.RegexTypes.BUSILICENSENO]);
            regexArr.push([params.storeName, constants.RegexTypes.MERCHANTFULLNAME]);
            regexArr.push([params.storeKind, constants.RegexTypes.MAINBUSINESS]);
            regexArr.push([params.registerAddress, constants.RegexTypes.REGISTEREDADDR]);
            regexArr.push([params.storeMan, constants.RegexTypes.PROPRIETORNAME]);
            (this.data.storeManIdentity !== umfUtils.removeSpace(params.storeManIdentity)) &&
            regexArr.push([umfUtils.removeSpace(params.storeManIdentity), constants.RegexTypes.ID_CARD]);

        }

        let errorMsg = regexUtils.regexTypesWithMsg(regexArr);
        if (errorMsg) {
            $Toptips.error({text: errorMsg});
            return false;
        }
        return true;
    },

    /**
     * 请求详情
     *
     * @param params
     * @private
     */
    _requestDetails: function () {
        let params = {
            storeId: this.data.storeId
        };

        network_utils.buildRequest(constants.Interfaces.FUNC_MERCHANT_DETAIL, params, {
            doHttpSucess: (response) => {
                if (constants.RetCodes.SUCCESS === response.retCode) {
                  //因为请求详情的是IMPay，所以第一个参数传false,标识不是POS
                    let state = new stateUtils.registProcssState(false,response["state"]);
                    this.setData({
                        requestOk: true,
                        storeState: state,
                        type:response["type"],
                        opinion: response["opinion"],
                        canMobileModify: response["canMobileModify"],

                        storeManIdentity: response["storeManIdentity"],
                        baseInfoArr: _getBaseInfoArr(this,response, state, this.data.fromType),
                        noInfoArr: _getNoInfoArr(this,response, state, this.data.fromType),
                        productsArr: _getProductsArr(response, state),

                        storeCategory: response["storeCategory"],
                        storeAddress: response["storeAddress"],
                        payeeInidcardValid: response["payeeInidcardValid"],
                        storeManIdentityValid: response["storeManIdentityValid"],
                        registerDate: response["registerDate"],
                    });
                    return true;
                }
                return false;
            }
        }).send();

    },
    /**
     * 提交修改
     *
     * @param params
     * @private
     */
    _requestSubmit: function (params) {
        network_utils.buildRequest(constants.Interfaces.FUNC_MERCHANT_MODIFY, params, {
            doHttpSucess: (response) => {
                if (constants.RetCodes.SUCCESS === response.retCode) {
                    umfToast.showToast('提交成功');
                    setTimeout(()=> {
                        wx.navigateBack({
                            delta: 1
                        });
                    }, 1000);
                }
                return false;
            }
        }).send();
    },
    
    /**
     * [结算账单优化工单]显示标签picker
     * @param e
     */
    showLocalNormalPicker: function (e) {
        let index = e.currentTarget.dataset.index;
        if (this.data.__nap && this.data.__nap[index] && this.data.__nap[index].firstList && this.data.__nap[index].firstList.length > 0) {
            this.showNormalPicker(e);
        } else {
            $Toast.showText("暂无历史输入记录,请手动输入标签内容");
        }
    },

    /**
     * [结算账单优化工单]初始化pickerview
     * [立马付运营优化二期]
     * @private
     */
    _initPickerView() {
        //初始化pickerview
        let storeEmailList = app.globalData.agentCache.storeEmail;

        let labelList1 = umfUtils.getStorageSync(constants.Keys.ANNO_LIST_1);
        let labelList2 = umfUtils.getStorageSync(constants.Keys.ANNO_LIST_2);

        let normalList = [];
        // labelList1 && labelList1.length > 0 && normalList.push(this._convertAnnoList(labelList1));
        // labelList2 && labelList2.length > 0 && normalList.push(this._convertAnnoList(labelList2));
        // storeEmailList && storeEmailList.length > 0 && normalList.push(this._convertAnnoList(storeEmailList));
        normalList.push(labelList1 && labelList1.length > 0 ? this._convertAnnoList(labelList1) : { first: [] });
        normalList.push(labelList2 && labelList2.length > 0 ? this._convertAnnoList(labelList2) : { first: [] });
        normalList.push(storeEmailList && storeEmailList.length > 0 ? this._convertAnnoList(storeEmailList) : { first: [] });

        this.initLinkagePicker([busTypes, location]);
        normalList.length > 0 && this.initNormalPicker(normalList);
    },

    /**
     * [结算账单优化工单] 转化annoList
     * @param annoList
     * @returns {{first: Array}}
     * @private
     */
    _convertAnnoList(labelList){
        let maper = (item)=> {
            return {label: item};
        };

        return {first: labelList.map(maper)};
    },

    /**
     * [立马付运营优化二期] 代理商账号维度保存商户邮箱
     * @param storeEmail
     * @private
     */
    _saveStoreEmail(storeEmail) {
        if (storeEmail) {
            let agentCache = app.globalData.agentCache;
            agentCache.storeEmail = this._getAnnoList(storeEmail, agentCache.storeEmail);
            saveAgentCache(agentCache);
        }
    },

    /**
     * [结算账单优化工单] 保存最近使用的标签
     * @param labelOne
     * @param labelTwo
     * @private
     */
    _saveAnnotations(labelOne, labelTwo) {
        let labelList1 = umfUtils.getStorageSync(constants.Keys.ANNO_LIST_1);
        let labelList2 = umfUtils.getStorageSync(constants.Keys.ANNO_LIST_2);
        labelList1 = this._getAnnoList(labelOne, labelList1);
        labelList2 = this._getAnnoList(labelTwo, labelList2);

        StringUtils.safeTrim(labelOne) && umfUtils.setStorageSync(constants.Keys.ANNO_LIST_1, labelList1);
        StringUtils.safeTrim(labelTwo) && umfUtils.setStorageSync(constants.Keys.ANNO_LIST_2, labelList2);
    },

    _getAnnoList(label, labelList) {
        if (label) {
            labelList = labelList ? labelList : [];
            let index = labelList.indexOf(label);
            if (index < 0) {
                //记录中没有
                labelList.unshift(label);
                if (labelList.length > 10) {
                    //最近10条
                    labelList = labelList.slice(0, 10);
                }
            } else {
                //记录中有
                labelList.splice(index, 1);
                labelList.unshift(label);
            }
        }
        return labelList;
    }
}, pickerView));

function _getBaseInfoArr(page,result, storeState, fromType=FromTypes.FROM_LIST) {
    let arr = [];
    if (result) {
      if ( result.type==1) {
            //批量入网的全部不能修改
            storeState.storeingDone && arr.push({ title: "商家简称", tag: "storeShortName", disabled: true, content: result["storeShortName"]});
            storeState.storeingDone && arr.push({ title: "商户类别", tag: "storeCategory", disabled: true, content: PickerUtils.getLinkedHZByCode(busTypes, result["storeCategory"]).join("/")});
            result["payeeName"] && arr.push({ title: "收款人姓名", tag: "payeeName", disabled: true, content: result["payeeName"] });
            result["payeeIdentity"] && arr.push({ title: "身份证号码", tag: "payeeIdentity", disabled: true, content: result["payeeIdentity"]});
            result["payeeInidcardValid"] && arr.push({ title: "证件有效期", tag: "payeeInidcardValid", disabled: true, content: result["payeeInidcardValid"]});
            result["payeeMobile"] && arr.push({ title: "收款人手机", tag: "payeeMobile", disabled: true, content: result["payeeMobile"]});
            storeState.storeingDone && arr.push({ title: "商户地址", tag: "storeAddress", disabled: true, content: PickerUtils.getLinkedHZByCode(location, result["storeAddress"]).join("/")});
            storeState.storeingDone && arr.push({ title: "详细地址", tag: "storeFullAddress", disabled: true, content: result["storeFullAddress"] });
            result["salesmanId"] && arr.push({ title: "业务员", tag: "salesmanId", disabled: true, content: result["salesmanId"] });
            //[立马付运营优化二期]
            storeState.storeingDone && arr.push({ title: "商户邮箱", tag: "storeEmail", disabled: true, content: result["email"] });
            storeState.storeingDone && arr.push({ title: "标签一", tag: "labelOne", disabled: true, content: result["labelOne"] });
            storeState.storeingDone && arr.push({ title: "标签二", tag: "labelTwo", disabled: true, content: result["labelTwo"] });
	}
        if (fromType === FromTypes.FROM_LIST && storeState.isPos) {
            //POS的场合全部显示并且不能修改
            arr.push({ title: "商家简称", tag: "storeShortName", disabled: true, content: result["storeShortName"]});
            arr.push({ title: "商户类别", tag: "storeCategory", disabled: true, content: PickerUtils.getLinkedHZByCode(busTypes, result["storeCategory"]).join("/")});
            arr.push({ title: "收款人姓名", tag: "payeeName", disabled: true, content: result["payeeName"] });
            arr.push({ title: "身份证号码", tag: "payeeIdentity", disabled: true, content: result["payeeIdentity"]});
            if (result["payeeInidcardValid"] != "2099-09-09") {
              page.setData({
                payeeDeadDate: true
              })
            }
            arr.push({ title: "证件有效期", tag: "payeeInidcardValid", disabled: true, content: result["payeeInidcardValid"]});
            arr.push({ title: "收款人手机", tag: "payeeMobile", disabled: true, content: result["payeeMobile"]});
            arr.push({ title: "商户地址", tag: "storeAddress", disabled: true, content: PickerUtils.getLinkedHZByCode(location, result["storeAddress"]).join("/")});
            arr.push({ title: "详细地址", tag: "storeFullAddress", disabled: true, content: result["storeFullAddress"] });
	        arr.push({ title: "业务员", tag: "salesmanId", disabled: true, content: result["salesmanId"] });
	        //[立马付运营优化二期]
            arr.push({ title: "商户邮箱", tag: "storeEmail", disabled: true, content: result["email"] });
            arr.push({ title: "标签一", tag: "labelOne", disabled: true, content: result["labelOne"] });
            arr.push({ title: "标签二", tag: "labelTwo", disabled: true, content: result["labelTwo"] });
        } else if (fromType === FromTypes.FROM_LIST&&result.type==0 && storeState.isImPay || fromType === FromTypes.FROM_SEARCH) {
            //立马付的场合视情况可以修改
            storeState.storeingDone && arr.push({ title: "商家简称", tag: "storeShortName", disabled: false, content: result["storeShortName"]});
            storeState.storeingDone && arr.push({ title: "商户类别", tag: "storeCategory", disabled: false, content: PickerUtils.getLinkedHZByCode(busTypes, result["storeCategory"]).join("/")});
            result["payeeName"] && arr.push({ title: "收款人姓名", tag: "payeeName", disabled: true, content: result["payeeName"] });
            result["payeeIdentity"] && arr.push({ title: "身份证号码", tag: "payeeIdentity", disabled: true, content: result["payeeIdentity"]});
            if (result["payeeInidcardValid"]!="2099-09-09"){
              page.setData({
                payeeDeadDate:true
              })
            }
            result["payeeInidcardValid"] && arr.push({ title: "证件有效期", tag: "payeeInidcardValid", disabled: false, content: result["payeeInidcardValid"]});
            result["payeeMobile"] && arr.push({ title: "收款人手机", tag: "payeeMobile", disabled: parseInt(result["canMobileModify"]) === 1, content: result["payeeMobile"]});
            storeState.storeingDone && arr.push({ title: "商户地址", tag: "storeAddress", disabled: false, content: PickerUtils.getLinkedHZByCode(location, result["storeAddress"]).join("/")});
            storeState.storeingDone && arr.push({ title: "详细地址", tag: "storeFullAddress", disabled: false, content: result["storeFullAddress"] });
            result["salesmanId"] && arr.push({ title: "业务员", tag: "salesmanId", disabled: true, content: result["salesmanId"] });
            //[立马付运营优化二期]
            storeState.storeingDone && arr.push({ title: "商户邮箱", tag: "storeEmail", disabled: false, content: result["email"] });
            // storeState.storeingDone && arr.push({ title: "客服电话", tag: "phone", disabled: false, content: result["phone"]  });//固话
            storeState.storeingDone && arr.push({ title: "标签一", tag: "labelOne", disabled: false, content: result["labelOne"] });
            storeState.storeingDone && arr.push({ title: "标签二", tag: "labelTwo", disabled: false, content: result["labelTwo"] });
	} 
 
    }
    return arr;
}

function _getNoInfoArr(page,result, storeState, fromType=FromTypes.FROM_LIST) {
    let arr = [];
    if (result && constants.BusTypes.COMPANY === result["storeType"]) {
        if (fromType === FromTypes.FROM_LIST && storeState.isPos) {
            arr.push({ title: "营业执照号", tag: "licenseNo", disabled: true, content: result["licenseNo"] });
            arr.push({ title: "商户全称", tag: "storeName", disabled: true, content: result["storeName"] });
            arr.push({ title: "经营者姓名", tag: "storeMan", disabled: true, content: result["storeMan"] });
            arr.push({ title: "身份证号码", tag: "storeManIdentity", disabled: true, content: umfUtils.formatIDCard(result["storeManIdentity"])});
            if (result["storeManIdentityValid"] != "2099-09-09") {
              page.setData({
                storeManDeadDate: true
              })
            }
            arr.push({ title: "证件有效期", tag: "storeManIdentityValid", disabled: true, content: result["storeManIdentityValid"]});
            arr.push({ title: "注册日期", tag: "registerDate", disabled: true, content: result["registerDate"] });
            arr.push({ title: "主营业务", tag: "storeKind", disabled: true, content: result["storeKind"] });
            arr.push({ title: "注册地址", tag: "registerAddress", disabled: true, content: result["registerAddress"] });
        } else if (storeState.isImPay && storeState.storeingDone && result.type==0) {
            result["licenseNo"] && arr.push({ title: "营业执照号", tag: "licenseNo", disabled: false, content: result["licenseNo"] });
            result["storeName"] && arr.push({ title: "商户全称", tag: "storeName", disabled: false, content: result["storeName"] });
            result["storeMan"] && arr.push({ title: "经营者姓名", tag: "storeMan", disabled: false, content: result["storeMan"] });
            result["storeManIdentity"] && arr.push({ title: "身份证号码", tag: "storeManIdentity", disabled: false, content: result["storeManIdentity"]});
            if (result["storeManIdentityValid"] != "2099-09-09") {
              page.setData({
                storeManDeadDate: true
              })
            }
            result["storeManIdentityValid"] && arr.push({ title: "证件有效期", tag: "storeManIdentityValid", disabled: false, content: result["storeManIdentityValid"]});
            result["registerDate"] && arr.push({ title: "注册日期", tag: "registerDate", disabled: false, content: result["registerDate"] });
            result["storeKind"] && arr.push({ title: "主营业务", tag: "storeKind", disabled: false, content: result["storeKind"] });
            result["registerAddress"] && arr.push({ title: "注册地址", tag: "registerAddress", disabled: false, content: result["registerAddress"] });
        } else if (result.type==1) {
            result["licenseNo"] && arr.push({ title: "营业执照号", tag: "licenseNo", disabled: true, content: result["licenseNo"] });
            result["storeName"] && arr.push({ title: "商户全称", tag: "storeName", disabled: true, content: result["storeName"] });
            result["storeMan"] && arr.push({ title: "经营者姓名", tag: "storeMan", disabled: true, content: result["storeMan"] });
            result["storeManIdentity"] && arr.push({ title: "身份证号码", tag: "storeManIdentity", disabled: true, content: result["storeManIdentity"]});
            result["storeManIdentityValid"] && arr.push({ title: "证件有效期", tag: "storeManIdentityValid", disabled: true, content: result["storeManIdentityValid"]});
            result["registerDate"] && arr.push({ title: "注册日期", tag: "registerDate", disabled: true, content: result["registerDate"] });
            result["storeKind"] && arr.push({ title: "主营业务", tag: "storeKind", disabled: true, content: result["storeKind"] });
            result["registerAddress"] && arr.push({ title: "注册地址", tag: "registerAddress", disabled: true, content: result["registerAddress"] });
        }
    }
    return arr;
}

function _getProductsArr(result, storeState) {
    let arr = [];
    if (result && storeState.productingDone) {
        storeState.isImPay && arr.push({ title: "立马付", tag: constants.Products[0].tag});
        // storeState.isPos && arr.push({ title: "POS机", tag: constants.Products[1].tag});
    }
    return arr;
}